from aiogram import Bot, Router
from aiogram.filters import Command, CommandObject
from aiogram.types import Message

from factories import get_screen
from sessions import user_sessions
from utils import alert_admin, delete_message

router = Router()


@router.message(Command("start"))
async def _get_cmd_start(message: Message, bot: Bot):
    # register new user
    user_sessions[message.from_user.id] = {}
    # remove /start command
    await delete_message(bot, message)
    # generate message for Admin
    text = [
        "<b>[Новый пользователь в боте]</b>",
        f"@{message.from_user.username}",
        f"ФИО: {message.from_user.first_name} {message.from_user.last_name}",
        f"ID: {message.from_user.id}",
        f"Human: {not message.from_user.is_bot}",
        f"Premium: {message.from_user.is_premium}",
    ]
    # send message to Admin
    await alert_admin(bot, "\n".join(text))
    screen = get_screen('root')
    # send Hello text
    await message.answer(screen.content, protect_content=True)


@router.message(Command("info"))
async def _get_cmd_info(message: Message, bot: Bot):
    # register new session for user
    # if he doesn't use /start command
    session = user_sessions.get(message.from_user.id, {})
    # get screen
    screen = get_screen("root")
    # remove comand
    await delete_message(bot, message)
    # send screen to user
    if screen:
        await message.answer(screen.content, reply_markup=screen.keyboard, protect_content=True)

@router.message(Command(commands=["contacts", "insurance"]))
async def _get_cmd_contacts_insurance(message: Message, bot: Bot, command: CommandObject):
    # register new session for user
    # if he doesn't use /start command
    session = user_sessions.get(message.from_user.id, {})
    # get screen
    screen = get_screen(command.command)
    # remove comand
    await delete_message(bot, message)
    # send screen to user
    if screen:
        await message.answer(screen.content, reply_markup=screen.keyboard, protect_content=True)
